<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MemberService\MemberMessageService;
use Hyperf\Di\Annotation\Inject;

/**
 * 消息中心
 * @author huj
 * @Controller(prefix="/webapi/v1/message")
 * @Middleware(WebApiMiddleware::class)
 */
class MessageController extends AbstractController 
{
     /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var MemberMessageService
     */
    protected $memberMessageService;

    /**
     * 用户消息中心
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request)
    {
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->getInfo($param);
    }

    /**
     * 消息列表
     * @RequestMapping(path="lists", methods="get,post")
     */
    public function lists(RequestInterface $request)
    {
        $param        = $request->inputs(['type','page','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->getMessage($param);
    }

    /**
     * 插入消息
     * @RequestMapping(path="add", methods="get,post")
     */
    public function add(RequestInterface $request)
    {
        $param        = $request->inputs(['content','title','url']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->insertMessage($param);
    }

    /**
     * 新系统消息列表
     * @RequestMapping(path="getlists", methods="get,post")
     */
    public function getlists(RequestInterface $request)
    {
        $param        = $request->inputs(['cid','page','limit','mnid','mn_sid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->newGetMessage($param);
    }

    /**
     * 新系统消息详情
     * @RequestMapping(path="getdetail", methods="get,post")
     */
    public function getdetail(RequestInterface $request)
    {
        $param        = $request->inputs(['id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->newGetDetail($param);
    }

    /**
     * 获取首个信息
     * @RequestMapping(path="getFirst", methods="get,post")
     */
    public function getFirst(RequestInterface $request)
    {
        $param        = $request->inputs(['mn_sid','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberMessageService->getFirstMsg($param);
    }
}